package city.spring.modules.medicine.controller;

import city.spring.modules.medicine.entity.MedicinewarehousingMedicineExtEntity;
import city.spring.modules.medicine.repository.MedicineRepository;
import city.spring.modules.medicine.repository.MedicinewarehousingMedicineExtRepository;
import city.spring.modules.medicine.service.MedicineService;
import city.spring.modules.medicine.service.MedicinewarehousingMedicineExtService;
import city.spring.modules.medicine.service.MedicinewarehousingService;
import city.spring.modules.medicine.vo.MedicinewarehousingMedicineVO;
import city.spring.utils.MyBatisUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Controller：药品入库与货架关联
 *
 * @author 谢金婷
 * @date 2020-07-20 02:23:26
 */
@RestController
@RequestMapping("/medicinewarehousing/{warehousingId}/medicine")
public class MedicinewarehousingMedicineController extends ApiController {
    private final MedicinewarehousingMedicineExtService medicinewarehousingShelfExtService;
    private final MedicinewarehousingMedicineExtRepository warehousingShelfExtRepository;
    private final MedicinewarehousingService medicinewarehousingService;
    private final MedicineService medicineService;
    private final MedicineRepository medicineRepository;
    /**
     * 实体类可排序字段
     */
    private final List<SFunction<MedicinewarehousingMedicineExtEntity, ?>> entityOrderFields;

    public MedicinewarehousingMedicineController(MedicinewarehousingMedicineExtService medicinewarehousingShelfExtService, MedicinewarehousingMedicineExtRepository warehousingShelfExtRepository, MedicinewarehousingService medicinewarehousingService, MedicineService medicineService, MedicineRepository medicineRepository) {
        this.medicinewarehousingShelfExtService = medicinewarehousingShelfExtService;
        this.warehousingShelfExtRepository = warehousingShelfExtRepository;
        this.medicinewarehousingService = medicinewarehousingService;
        this.medicineService = medicineService;
        this.medicineRepository = medicineRepository;
        entityOrderFields = new ArrayList<>();
        entityOrderFields.add(MedicinewarehousingMedicineExtEntity::getId);
        entityOrderFields.add(MedicinewarehousingMedicineExtEntity::getMedicinelwarehousingId);
        entityOrderFields.add(MedicinewarehousingMedicineExtEntity::getWarehousingquantity);
        entityOrderFields.add(MedicinewarehousingMedicineExtEntity::getTotal);
    }

    @ModelAttribute
    public void getWarehousingId(@PathVariable String warehousingId) {
        if (warehousingId == null) {
            throw new RuntimeException("入库单ID必须不为空");
        }
        System.out.println("warehousingId" + warehousingId);
    }

    /**
     * 获取全部的 <strong>药品入库与货架关联</strong> 列表
     */
    @GetMapping("all")
    public Object listAll(@PageableDefault Pageable pageable, MedicinewarehousingMedicineExtEntity entity) {
        LambdaQueryChainWrapper<MedicinewarehousingMedicineExtEntity> lambdaQuery = buildLambdaQuery(entity);
        MyBatisUtils.lambdaQueryAddOrder(lambdaQuery, pageable, entityOrderFields);
        return success(lambdaQuery.list());
    }

//    /**
//     * 分页获取 <strong>药品入库与货架关联</strong> 列表
//     *
//     * @param pageable 分页参数信息
//     */
//    @GetMapping
//    public Object list(@PageableDefault Pageable pageable, MedicinewarehousingShelfExtEntity entity) {
//        LambdaQueryChainWrapper<MedicinewarehousingShelfExtEntity> lambdaQuery = buildLambdaQuery(entity);
//        MyBatisUtils.lambdaQueryAddOrder(lambdaQuery, pageable, entityOrderFields);
//        Page<MedicinewarehousingShelfExtEntity> page = lambdaQuery.page(MyBatisUtils.toPage(pageable, false));
//        return success(page);
//    }

    /**
     * 获取物资出库所有货架列表
     *
     * @param warehousingId
     * @return
     */
    @GetMapping
    public Object list(@PathVariable String warehousingId) {
        return success(warehousingShelfExtRepository.getWarehousingShelflevels(warehousingId));
    }

//    /**
//     * 获取一个 <strong>药品入库与货架关联</strong>
//     *
//     * @param id 主键ID
//     */
//    @GetMapping("{id}")
//    public Object info(@PathVariable String id) {
//        return success(medicinewarehousingShelfExtService.getById(id));
//    }

    /**
     * @param warehousingId
     * @param extId
     * @return
     */
    @GetMapping("{extId}")
    public Object getInfo(@PathVariable String warehousingId, @PathVariable String extId) {
        return success(warehousingShelfExtRepository.getWarehousingShelflevel(warehousingId, extId));
    }

//    /**
//     * 添加一个 <strong>药品入库与货架关联</strong>
//     *
//     * @param entity 修改后的信息
//     */
//    @PostMapping
//    public Object add(@RequestBody MedicinewarehousingShelfExtEntity entity) {
//        medicinewarehousingShelfExtService.saveMedicinewarehousingShelfExt(entity);
//
//        HttpHeaders headers = new HttpHeaders();
//        headers.add(HttpHeaders.LOCATION, String.valueOf(entity.getId()));
//        return new ResponseEntity<>(headers, HttpStatus.CREATED);
//    }

    /**
     * 给入库单添加多个货架信息
     *
     * @param warehousingId 入库单ID
     * @param shelflevels   所添加的物资信息列表
     * @return
     */
    @PostMapping
    public Object addAll(@PathVariable String warehousingId, @RequestBody List<MedicinewarehousingMedicineExtEntity> shelflevels) {
        // 查出已有的数据
        List<MedicinewarehousingMedicineVO> dbShelflevels = warehousingShelfExtRepository.getWarehousingShelflevels(warehousingId);

        // 数据库已经存在的物资列表
        Set<String> dbShelflevelIdsSet = dbShelflevels.stream()
                .map(MedicinewarehousingMedicineExtEntity::getMedicineId)
                .collect(Collectors.toSet());
        // 过滤掉已经存在数据库的数据
        List<MedicinewarehousingMedicineExtEntity> needSaveShelflevels = shelflevels.stream()
                .filter(item -> {
                    item.setMedicinelwarehousingId(warehousingId);
                    String shelflevelId = item.getMedicineId();
                    // 过滤出不存在数据库中的数据
                    return shelflevelId != null && !dbShelflevelIdsSet.contains(shelflevelId);
                }).collect(Collectors.toList());

        if (!needSaveShelflevels.isEmpty()) {
            medicinewarehousingShelfExtService.saveBatch(needSaveShelflevels);
        }

//        // 根据入库单id查找关联的货架MaterialwarehousingShelfExtEntity
//        List<MedicinewarehousingShelfExtEntity> shelfExtEntities = warehousingShelfExtRepository.getWarehousingSls(warehousingId);
//        for (MedicinewarehousingShelfExtEntity shelfExtEntity : shelfExtEntities) {
//            System.out.println("shelfExtEntity" + shelfExtEntity);
//
//            /**
//             * 关联货架MaterialwarehousingShelfExtEntity的更新
//             */
//            //入库货架的入库数量
//            BigDecimal warehousingquantity = shelfExtEntity.getWarehousingquantity() == null ? BigDecimal.ZERO : shelfExtEntity.getWarehousingquantity();
//            // 根据入库单id获取入库信息
//            MedicinewarehousingEntity medicinewarehousingEntity = medicinewarehousingService.getById(shelfExtEntity.getMedicinelwarehousingId());
//            //根据物资id查找物资信息
//            MedicineEntity medicineEntity = medicineService.getById(medicinewarehousingEntity.getMedicineId());
//            System.out.println(medicineEntity);
//            //转换关系
//            BigDecimal relationship = medicinewarehousingEntity.getRelationship() == null ? BigDecimal.ZERO : medicinewarehousingEntity.getRelationship();
//            //计算计量数量=入库数量*转换关系
//            shelfExtEntity.setUnitmeasurementquantity(warehousingquantity.multiply(relationship));
//            System.out.println("shelfExtEntity.getUnitmeasurementquantity()" + shelfExtEntity.getUnitmeasurementquantity());
//            //计算总价
//            BigDecimal unitprice = medicinewarehousingEntity.getUnitprice() == null ? BigDecimal.ZERO : medicinewarehousingEntity.getUnitprice();
//            BigDecimal shelfunitmeasurementquantity = shelfExtEntity.getUnitmeasurementquantity() == null ? BigDecimal.ZERO : shelfExtEntity.getUnitmeasurementquantity();
//            shelfExtEntity.setTotal(shelfunitmeasurementquantity.multiply(unitprice));
//            System.out.println("shelfExtEntity.getTotal()" + shelfExtEntity.getTotal());
//            medicinewarehousingShelfExtService.updateMedicinewarehousingShelfExt(shelfExtEntity);
//
//            System.out.println("setIswarehouse" + medicineEntity.getIswarehouse());
//            // 第一次入库 是否入库的值=2
//            if (medicineEntity.getIswarehouse().compareTo(2) == 0) {
//                System.out.println("第一次入库");
//                /**
//                 * 入库后更新物资信息
//                 */
//                medicineEntity.setStorehouseId(medicinewarehousingEntity.getStorehouseId());
////                medicineEntity.setSpecifications(medicinewarehousingEntity.getSpecifications());
//                medicineEntity.setManufacturer(medicinewarehousingEntity.getManufacturer());
////                medicineEntity.setType(medicinewarehousingEntity.getType());
//                medicineEntity.setUnitprice(medicinewarehousingEntity.getUnitprice());
//                medicineEntity.setSupplierId(medicinewarehousingEntity.getSupplierId());
//                medicineEntity.setWarehousingquantity(shelfExtEntity.getUnitmeasurementquantity());
//                medicineEntity.setQuantity(shelfExtEntity.getUnitmeasurementquantity());
//                medicineEntity.setProductiondate(medicinewarehousingEntity.getProductiondate());
//                medicineEntity.setExpirationdate(medicinewarehousingEntity.getExpirationdate());
//                medicineEntity.setIswarehouse(1);
//                medicineEntity.setShelfId(shelfExtEntity.getShelflevelId());
//
//                medicineService.lambdaUpdate()
//                        .set(MedicineEntity::getStorehouseId, medicineEntity.getStorehouseId())
////                        .set(MedicineEntity::getSpecifications, medicineEntity.getSpecifications())
//                        .set(MedicineEntity::getManufacturer, medicineEntity.getManufacturer())
////                        .set(MedicineEntity::getType, medicineEntity.getType())
//                        .set(MedicineEntity::getUnitprice, medicineEntity.getUnitprice())
//                        .set(MedicineEntity::getSupplierId, medicineEntity.getSupplierId())
//                        .set(MedicineEntity::getWarehousingquantity, medicineEntity.getWarehousingquantity())
//                        .set(MedicineEntity::getQuantity, medicineEntity.getQuantity())
//                        .set(MedicineEntity::getProductiondate, medicineEntity.getProductiondate())
//                        .set(MedicineEntity::getExpirationdate, medicineEntity.getExpirationdate())
//                        .set(MedicineEntity::getIswarehouse, medicineEntity.getIswarehouse())
//                        .set(MedicineEntity::getShelfId, medicineEntity.getShelfId())
//                        .eq(MedicineEntity::getId, medicineEntity.getId())
//                        .update();
////                System.out.println("shelfExtEntities.size"+shelfExtEntities.size());
//
//                // 非第一次入库
//            } else if (medicineEntity.getIswarehouse().compareTo(1) == 0) {
//                System.out.println("非第一次入库" + shelfExtEntity.getShelflevelId());
//                // 如果货架id=入库的货架id 更新物资信息
//                if (medicineEntity.getShelfId().equals(shelfExtEntity.getShelflevelId())) {
//                    System.out.println("如果药品货架id=入库的货架id 更新药品信息" + shelfExtEntity.getShelflevelId());
//                    //如果货架相同就更新物资库存
//                    /**
//                     * 入库后更新物资库存
//                     */
//                    //更新入库数量=原来的入库数量+现在的入库数量
//                    BigDecimal mwarehousingquantity = medicineEntity.getWarehousingquantity() == null ? BigDecimal.ZERO : medicineEntity.getWarehousingquantity();
//                    medicineEntity.setWarehousingquantity(mwarehousingquantity.add(shelfExtEntity.getUnitmeasurementquantity()));
//                    System.out.println(mwarehousingquantity + "====" + shelfExtEntity.getUnitmeasurementquantity());
//                    // 更新库存=原来的库存+现在的入库数量
//                    BigDecimal mquantity = medicineEntity.getQuantity() == null ? BigDecimal.ZERO : medicineEntity.getQuantity();
//                    medicineEntity.setQuantity(mquantity.add(shelfExtEntity.getUnitmeasurementquantity()));
//
//                    medicineService.lambdaUpdate()
//                            .set(MedicineEntity::getWarehousingquantity, medicineEntity.getWarehousingquantity())
//                            .set(MedicineEntity::getQuantity, medicineEntity.getQuantity())
//                            .eq(MedicineEntity::getId, medicineEntity.getId())
//                            .update();
//                    // 如果货架id不相等，查找该入库货架下的药品是否有入库的药品，有则更新该药品库存，无则新建药品记录
//                } else if (!medicineEntity.getShelfId().equals(shelfExtEntity.getShelflevelId())) {
//                    System.out.println("如果货架id不相等" + shelfExtEntity.getShelflevelId());
//                    // 根据货架层次id在物资表查找该货架下的物资信息 materialEntities
//                    List<MedicineEntity> medicineEntities = medicineRepository.medicineByShelfId(shelfExtEntity.getShelflevelId());
//////                    System.out.println("非库"+shelfExtEntity.getShelflevelId());
////                    System.out.println("materialEntities"+materialEntities);
//////                    System.out.println("materialBaseEntity"+materialBaseEntity);
//                    // materialBaseEntities 为空 说明该仓库下没有该物资，新增物资计量
//                    if (medicineEntities == null || medicineEntities.size() == 0) {
//                        System.out.println("medicineEntities，新增物资");
//                        MedicineEntity medicineEntity1 = new MedicineEntity();
//                        medicineEntity1.setName(medicineEntity.getName());
//                        medicineEntity1.setCode(medicineEntity.getCode());
//                        medicineEntity1.setCategory(medicineEntity.getCategory());
//                        medicineEntity1.setSpecifications(medicineEntity.getSpecifications());
//                        medicineEntity1.setUnit(medicineEntity.getUnit());
//                        medicineEntity1.setUnitprice(medicineEntity.getUnitprice());
//                        medicineEntity1.setDosageunit(medicineEntity.getDosageunit());
//                        medicineEntity1.setSupplierId(medicineEntity.getSupplierId());
//                        medicineEntity1.setManufacturer(medicineEntity.getManufacturer());
//                        medicineEntity1.setType(medicineEntity.getType());
//                        medicineEntity1.setDescription(medicineEntity.getDescription());
//                        medicineEntity1.setWarehousingquantity(shelfExtEntity.getUnitmeasurementquantity());
//                        medicineEntity1.setQuantity(shelfExtEntity.getUnitmeasurementquantity());
//                        medicineEntity1.setStorehouseId(medicineEntity.getStorehouseId());
//                        medicineEntity1.setProductiondate(medicineEntity.getProductiondate());
//                        medicineEntity1.setExpirationdate(medicineEntity.getExpirationdate());
//                        medicineEntity1.setIswarehouse(medicineEntity.getIswarehouse());
//                        medicineEntity1.setShelfId(shelfExtEntity.getShelflevelId());
//                        medicineService.save(medicineEntity1);
//                        HttpHeaders headers = new HttpHeaders();
//                        headers.add(HttpHeaders.LOCATION, String.valueOf(medicineEntity.getId()));
//                        logger.info("medicineEntities.contains(medicineEntity：{}", medicineEntities.contains(medicineEntity));
//                    } else if (medicineEntities.contains(medicineEntity)) {
//                        System.out.println("medicineEntities包含medicineEntity");
//                        List<MedicineEntity> baseMedicine = medicineRepository.getByBaseMedicine(medicineEntity.getName(), medicineEntity.getCategory(), medicineEntity.getSpecifications(), medicineEntity.getUnit(), medicineEntity.getUnitprice(), medicineEntity.getDosageunit(), medicineEntity.getSupplierId(), medicineEntity.getManufacturer(), medicineEntity.getType(), medicineEntity.getStorehouseId(), medicineEntity.getProductiondate(), medicineEntity.getExpirationdate());
//                        System.out.println("baseMedicine:" + baseMedicine);
//                        for (MedicineEntity baseMedicine1 : baseMedicine) {
//                            if (baseMedicine1.getShelfId().equals(shelfExtEntity.getShelflevelId())) {
//                                System.out.println("货架id相等，更新该药品库存" + baseMedicine1);
//                                //更新入库数量=原入库数量+现在入库数量
//                                BigDecimal mwarehousingquantity = baseMedicine1.getWarehousingquantity() == null ? BigDecimal.ZERO : baseMedicine1.getWarehousingquantity();
//                                baseMedicine1.setWarehousingquantity(mwarehousingquantity.add(shelfExtEntity.getUnitmeasurementquantity()));
//                                // 更新库存=原库存+入库数量
//                                BigDecimal quantity = baseMedicine1.getQuantity() == null ? BigDecimal.ZERO : baseMedicine1.getQuantity();
//                                baseMedicine1.setQuantity(quantity.add(shelfExtEntity.getUnitmeasurementquantity()));
//                                medicineService.lambdaUpdate()
//                                        .set(MedicineEntity::getWarehousingquantity, baseMedicine1.getWarehousingquantity())
//                                        .set(MedicineEntity::getQuantity, baseMedicine1.getQuantity())
//                                        .eq(MedicineEntity::getId, baseMedicine1.getId())
//                                        .update();
//                            }
//                        }
//                    } else {
//                        System.out.println("medicineEntities不包含medicineEntity,新增药品记录");
//                        MedicineEntity medicineEntity1 = new MedicineEntity();
//                        medicineEntity1.setName(medicineEntity.getName());
//                        medicineEntity1.setCode(medicineEntity.getCode());
//                        medicineEntity1.setCategory(medicineEntity.getCategory());
//                        medicineEntity1.setSpecifications(medicineEntity.getSpecifications());
//                        medicineEntity1.setUnit(medicineEntity.getUnit());
//                        medicineEntity1.setUnitprice(medicineEntity.getUnitprice());
//                        medicineEntity1.setDosageunit(medicineEntity.getDosageunit());
//                        medicineEntity1.setSupplierId(medicineEntity.getSupplierId());
//                        medicineEntity1.setManufacturer(medicineEntity.getManufacturer());
//                        medicineEntity1.setType(medicineEntity.getType());
//                        medicineEntity1.setDescription(medicineEntity.getDescription());
//                        medicineEntity1.setWarehousingquantity(shelfExtEntity.getUnitmeasurementquantity());
//                        medicineEntity1.setQuantity(shelfExtEntity.getUnitmeasurementquantity());
//                        medicineEntity1.setStorehouseId(medicineEntity.getStorehouseId());
//                        medicineEntity1.setProductiondate(medicineEntity.getProductiondate());
//                        medicineEntity1.setExpirationdate(medicineEntity.getExpirationdate());
//                        medicineEntity1.setIswarehouse(medicineEntity.getIswarehouse());
//                        medicineEntity1.setShelfId(shelfExtEntity.getShelflevelId());
//                        medicineService.save(medicineEntity1);
//                        HttpHeaders headers = new HttpHeaders();
//                        headers.add(HttpHeaders.LOCATION, String.valueOf(medicineEntity.getId()));
//                    }
//                }
//            }
//        }
//
//        /**
//         * 更新入库信息
//         * 1.获取到当前入库记录
//         * 2.当前入库记录的货架信息
//         */
//        // 根据入库单id获取入库信息
//        MedicinewarehousingEntity medicinewarehousingEntity = medicinewarehousingService.getById(warehousingId);
//        if (shelfExtEntities.size() == 0) {
//            medicinewarehousingEntity.setTotalquantity(BigDecimal.ZERO);
//            medicinewarehousingEntity.setTotal(BigDecimal.ZERO);
//        } else {
//            BigDecimal totalquantity = new BigDecimal(0);
//            BigDecimal total = new BigDecimal(0);
//            for (MedicinewarehousingShelfExtEntity ms : shelfExtEntities) {
//                totalquantity = totalquantity.add(ms.getUnitmeasurementquantity());
//                total = total.add(ms.getTotal());
//
//            }
//            System.out.println("totalquantity:" + totalquantity);
//            System.out.println("total:" + total);
//            //统计总入库数量
//            medicinewarehousingEntity.setTotalquantity(totalquantity);
//            //统计总金额
//            medicinewarehousingEntity.setTotal(total);
//            // 执行更新方法
//            medicinewarehousingService.lambdaUpdate()
//                    .set(MedicinewarehousingEntity::getTotal, medicinewarehousingEntity.getTotal())
//                    .set(MedicinewarehousingEntity::getTotalquantity, medicinewarehousingEntity.getTotalquantity())
//                    .eq(MedicinewarehousingEntity::getId, medicinewarehousingEntity.getId())
//                    .update();
//
//        }


        return success(null);
    }


    //    /**
//     * 修改一个 <strong>药品入库与货架关联</strong>
//     *
//     * @param id     主键ID
//     * @param entity 修改后的信息
//     */
//    @PutMapping("{id}")
//    public Object update(@PathVariable String id, @RequestBody MedicinewarehousingShelfExtEntity entity) {
//        entity.setId(id);
//        medicinewarehousingShelfExtService.updateMedicinewarehousingShelfExt(entity);
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
    @PutMapping("{extId}")
    public Object update(@PathVariable String warehousingId, @PathVariable String extId, @RequestBody MedicinewarehousingMedicineExtEntity extEntity) {
        extEntity.setId(String.valueOf(extId));
        extEntity.setMedicinelwarehousingId(warehousingId);
        medicinewarehousingShelfExtService.updateMedicinewarehousingShelfExt(extEntity);
        return success(null);
    }

    /**
     * 删除一个 <strong>药品入库与货架关联</strong>
     *
     * @param id 主键ID
     */
    @DeleteMapping("{id}")
    public Object delete(@PathVariable String id) {
        medicinewarehousingShelfExtService.deleteMedicinewarehousingShelfExt(id);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除多个 <strong>药品入库与货架关联</strong>
     *
     * @param ids 主键ID列表
     */
    @DeleteMapping
    public Object deleteIds(@RequestBody List<String> ids) {
        medicinewarehousingShelfExtService.deleteMedicinewarehousingShelfExt(ids);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 构建查询条件内容
     *
     * @param entity 实体对象
     * @return lambda query chain wrapper
     */
    private LambdaQueryChainWrapper<MedicinewarehousingMedicineExtEntity> buildLambdaQuery(MedicinewarehousingMedicineExtEntity entity) {
        LambdaQueryChainWrapper<MedicinewarehousingMedicineExtEntity> lambdaQuery = medicinewarehousingShelfExtService.lambdaQuery();
        lambdaQuery.eq(StringUtils.isNotBlank(entity.getId()), MedicinewarehousingMedicineExtEntity::getId, entity.getId());
        lambdaQuery.eq(entity.getMedicinelwarehousingId() != null, MedicinewarehousingMedicineExtEntity::getMedicinelwarehousingId, entity.getMedicinelwarehousingId());
        lambdaQuery.eq(entity.getWarehousingquantity() != null, MedicinewarehousingMedicineExtEntity::getWarehousingquantity, entity.getWarehousingquantity());
        lambdaQuery.eq(entity.getTotal() != null, MedicinewarehousingMedicineExtEntity::getTotal, entity.getTotal());
        return lambdaQuery;
    }

    /**
     * 构建查询条件内容
     *
     * @param entity 实体对象
     * @return lambda query chain wrapper
     */
    private QueryWrapper<MedicinewarehousingMedicineExtEntity> buildQuery(MedicinewarehousingMedicineExtEntity entity) {
        QueryWrapper<MedicinewarehousingMedicineExtEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(entity.getId()), "id", entity.getId());
        wrapper.eq(entity.getMedicinelwarehousingId() != null, "medicinelwarehousing_id", entity.getMedicinelwarehousingId());
        wrapper.eq(entity.getWarehousingquantity() != null, "warehousingquantity", entity.getWarehousingquantity());
        wrapper.eq(entity.getTotal() != null, "total", entity.getTotal());
        return wrapper;
    }

}
